﻿using System;
using System.Collections.Generic;
using DevExpress.Xpo;
using System.Text;

namespace BusinessObjects
{
    public class TestUser : XPObject
    {
        public TestUser()
            : base()
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        public TestUser(Session session)
            : base(session)
        {
            // This constructor is used when an object is loaded from a persistent storage.
            // Do not place any code here.
        }

        public override void AfterConstruction()
        {
            base.AfterConstruction();
            // Place here your initialization code.
        }

        TaiKhoan fTaiKhoan;
        [Association(@"TestUserReferencesTaiKhoan")]
        public TaiKhoan TaiKhoan
        {
            get { return fTaiKhoan; }
            set { SetPropertyValue<TaiKhoan>("TaiKhoan", ref fTaiKhoan, value); }
        }

        //Fields
        TestProfile fProfile = null;
        public TestProfile Profile
        {
            get { return fProfile; }
            set
            {
                if (fProfile == value)
                    return;

                TestProfile prevOwner = fProfile;
                fProfile = value;

                if (IsLoading) return;

                if (prevOwner != null && prevOwner.User == this)
                    prevOwner.User = null;

                if (fProfile != null)
                    fProfile.User = this;
                OnChanged("Profile");
            }
        }

        string fLastName;
        [Size(50)]
        public string LastName
        {
            get { return fLastName; }
            set { SetPropertyValue<string>("LastName", ref fLastName, value); }
        }

        string fFirstName;
        [Size(50)]
        public string FirstName
        {
            get { return fFirstName; }
            set { SetPropertyValue<string>("FirstName", ref fFirstName, value); }
        }
    }
}
